package com.example.cabinet.lock.lib;

public class LockControl {

    static {
        String os = System.getProperty("os.name");
        String dir = System.getProperty("user.dir");
        System.out.println(os);
        System.out.println(System.getProperty("user.dir"));
        if (os.startsWith("Windows")) {
            System.load(dir + "\\LockControl-ZZ.dll");
        } else {
            System.load(dir + "/libLockControl-ZZ.so");
        }
    }

    public LockControl() {

    }

    private long handle;
    private String ip;

    public static final int SUCCESS = 0;

    public interface OnLockControlListener {
        void onClosed(String ip, int port);
    }

    private OnLockControlListener listener;

    public void setOnLockControlListener(OnLockControlListener listener) {
        this.listener = listener;
    }

    protected void onClosed(int port) {
        if (listener != null) {
            listener.onClosed(ip, port);
        }
    }

    public native int connect(String ip, int port, int cabinetId);

    public native int disconnect();

    public native int open(int port);

    public native int startInspect();

    public native int stopInspect();

    public native int getStatus(byte[] status);
}
